/**
 *
 * @author DorcasBless
 * you can find the Synaxarium at http://code.google.com/p/synaxarium/
 * April, 2009
 * Version 1.0.0
 *
 */

package com.christian;

import javax.microedition.lcdui.*;

public class SMSForm extends Form implements CommandListener {

    /** Creates a new instance of SMSMidlet */
    private String phoneNo;
    private SynMIDlet synMIDlet;
    private Command sendCommand = new Command("\u0627\u0631\u0633\u0644", Command.OK, 0);
    private Command backCommand = new Command("\u0631\u062C\u0648\u0639", Command.BACK, 0);
    private TextField toTextField = new TextField("\u0627\u0644\u0649:", null, 20, TextField.PHONENUMBER);
    private TextField MessageTextField = new TextField("\u0627\u0644\u0631\u0633\u0627\u0644\u0629:", null, 10000, TextField.ANY);

    public SMSForm(SynMIDlet synMIDlet) {
        super("\u0627\u0631\u0633\u0644 \u0642\u0635\u0629 \u0627\u0644\u064A\u0648\u0645");
        this.synMIDlet = synMIDlet;
        append(toTextField);
        append(MessageTextField);
        addCommand(backCommand);
        addCommand(sendCommand);
        setCommandListener(this);
    }


    public void commandAction(Command command, Displayable displayable) {

        if (command == sendCommand) {
            if (toTextField.getString() != null && !"".equals(toTextField.getString().trim())) {
                //load list
                phoneNo = getToTextField().getString();
                SMSSender sms = new SMSSender("sms://" + phoneNo, getMessageTextField().getString(), synMIDlet);
                (new Thread(sms)).start();
            }
            else
            {
                synMIDlet.getAlertWarn().setString("\u0628\u0631\u062C\u0627\u0621 \u0643\u062A\u0627\u0628\u0629 \u0631\u0642\u0645 \u0627\u0644\u0645\u0631\u0633\u0644 \u0627\u0644\u064A\u0647");
                synMIDlet.showWarnAlert();
            }

        } else if (command == backCommand) {
                synMIDlet.showSameMainScreen();
        }
    }

    /**
     * @return the toTextField
     */
    public TextField getToTextField() {
        return toTextField;
    }

    /**
     * @param toTextField the toTextField to set
     */
    public void setToTextField(TextField toTextField) {
        this.toTextField = toTextField;
    }

    /**
     * @return the MessageTextField
     */
    public TextField getMessageTextField() {
        return MessageTextField;
    }

    /**
     * @param MessageTextField the MessageTextField to set
     */
    public void setMessageTextField(TextField MessageTextField) {
        this.MessageTextField = MessageTextField;
    }
}



